// pages/assign_detail/assign_detail.js
var app = getApp();
var util = require('../../utils/util.js');
var applet_park_api_url = app.globalData.applet_park_api_url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkname: '',
    expectedEndTime1: '',
    expectedStartTime1: '',
    cheeckPlainid: '',
    detail: {},
    receiverName: '',
    receiverId: '',
    receivermb: '',
    tid: '',
    groupId: '',
  },
  toStaflist() {
    wx.navigateTo({
      url: '../staff_list/staff_list?cheeckPlainid=' + this.data.cheeckPlainid + "&tid=" + this.data.tid,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.name) {
      this.data.checkname = options.name;
    }
    if (options.et) {
      this.data.expectedEndTime1 = options.et;
    }
    if (options.st) {
      this.data.expectedStartTime1 = options.st;
    }
    if (options.id) {
      this.data.cheeckPlainid = options.id;
    }
    if (options.tid) {
      this.data.tid = options.tid;
    }
    if (options.groupId) {
      this.data.groupId = options.groupId;
    }
    this.setData(this.data);
    this.loadData();
  },
  loadData() {
    var that = this;


    wx.request({
      url: applet_park_api_url + '/api/checkTasks/' + that.data.cheeckPlainid,
      method: 'get',
      success: function (res) {

        if (res.data.code == 0) {
          var lists = res.data.data;

          that.setData({
            lists: lists
          })

        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        }
      },
      fail: function (res) {}

    })
  },
  saveAssin() {
    var that = this;
    if (!that.data.receiverId) {
      wx.showToast({
        title: '请选择巡检组',
      });
      return
    }
    wx.request({
      // url: applet_park_api_url + '/api/checkTasks/' + that.data.tid + "?receiverId=" + that.data.receiverId,
      url: applet_park_api_url + '/api/checkPlans/' + that.data.cheeckPlainid + '/groups/' + that.data.groupId + '?updateGroupId=' + that.data.receiverId,
      method: 'PUT',
      success: function (res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '保存成功',
          });
          wx.navigateTo({
            url: '../patrol_list/patrol_list',
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络异常，稍后重试',
        });
      }

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})